/**
 * Created by 修 on 2015/2/14.
 */
function card(options){
    var defaults = {
        time:"2015年2月14日 01:10:08",
        content:"方交凤我爱你.你的下一句话也许就是还忘不了他，也许是你发现你还是不喜欢我.但是我还是愿意每次都相信你接受我了",
        comment:["修：你就是不喜欢我","修：你就是要我当你的备胎！"],
        aid:0,
        good:0,
        bad:0
    }
    options = $.extend(defaults,options);
    var dom =
            '<div class="article">'+
                '<div class="article_title">'+options.time+'</div>'+
                '<div class="article_body">'+options.content+'</div>'+
                '<div class="article_icon">'+
                    '<span><i class="icon-thumbs-up"></i><em>'+options.good+'</em></span>'+
                    '<span><i class="icon-thumbs-down"></i><em>'+options.bad+'</em></span>'+
                    '<span><i class="icon-edit"></i></span>'+
                '</div>'+
                '<div class="comment_input" style="display: none">'+
                    '<input name="comment"/>'+
                    '<span class="comment_send"><i class="icon-ok"></i></span>'+
                '</div>'+
                '<ul class="comment">';
    for(var i in options.comment){
        dom+='<li>'+options.comment[i]+'</li>';
    }
    dom+="</ul></div>";
    dom = $(dom);
    $(".content").append(dom);
    var comment_icon = dom.find(".icon-edit");//评论按钮
    var comment_input = dom.find("input[name='comment']");//输入框
    var comment = dom.find(".comment");//评论区
    var send_icon = dom.find(".comment_send");//发送按钮
    var input_div = dom.find(".comment_input");
    var good = dom.find(".icon-thumbs-up");
    var bad = dom.find(".icon-thumbs-down");

    comment_icon.on("click",function(){
        input_div.toggle();
        comment_input.focus();
    });
    comment_input.on("keypress",function(e){
        if(e.keyCode==13){
            send_icon.trigger("click");
        }
    });
    send_icon.on("click",function(){
        var words = comment_input.val();
        comment_input.val("");
        $("<li>").html(user+"："+words).prependTo(comment);
        input_div.hide();
        $.post(base_url+"article/comment/"+options.aid,{comment:words},function(){});
    });
    good.on("click",function(){
        $.get(base_url+"article/praise/"+options.aid);
        $(this).next("em").html(parseInt($(this).next("em").html())+1);
    })
    bad.on("click",function(){
        $.get(base_url+"article/nay/"+options.aid);
        $(this).next("em").html(parseInt($(this).next("em").html())+1);
    })
    function add_comment(user,time,comment){

    }
    return dom;
}
